#include"processbar.h"

const char* lable = "|/-\\";
void process()
{
  char buffer[NUM];
  memset(buffer,'\0',sizeof(buffer));
  int cnt = 0;
  buffer[0] = Head;
 // int n = strlen()
  while(cnt<=100) //它会循环101次
  {
    printf("[%-100s][%3d%%][%c]\r",buffer,cnt,lable[cnt%4]);
    fflush(stdout);
    buffer[cnt]=Body;
    cnt++;  //因为到最后cnt是100也能进，所以有效字符会变成101，给\0加一个，所以给102
    if(cnt<100)
      buffer[cnt]=Head;
    usleep(50000);
  }
  printf("\n");
}


char buffer[NUM] = {0};
void process_flush(double rate){
  static int cnt = 0;
  if(rate <= 1.0) buffer[0] = Head;
  printf("[%-100s][%5.1f%%][%c]\r",buffer,rate,lable[cnt%4]);
  fflush(stdout);
  buffer[(int)rate]=Body;
  if((int)rate+1 < 100) //+1 very improtant
    buffer[(int)rate+1]=Head;

  if(rate>=100.0) printf("\n");
  cnt++;
  cnt = cnt % 4;
}


